import WebMonitor from '../index'; // 引入我们的监控SDK

export default {
  async install(app, options) {
    // 创建监控实例
    const monitor = new WebMonitor({
      appId: options.appId || 'vue-app',
      userId: options.userId,
      // reportUrl: options.reportUrl || 'https://your-api.com/report', // 注释掉上报地址
      batchSize: options.batchSize || 10,
      batchTimeout: options.batchTimeout || 5000
    });
    // 将监控实例挂载到全局属性
    app.config.globalProperties.$monitor = monitor;
    console.log(monitor);
    
    // 也可以通过 provide/inject 方式提供
    app.provide('monitor', monitor);

    // 添加全局错误处理
    app.config.errorHandler = (error, vm, info) => {
      monitor.reporter.send('error', {
        type: 'vue',
        message: error.message,
        stack: error.stack,
        info,
        component: vm?.$options?.name || 'anonymous',
        timestamp: Date.now()
      })
    }

    // 添加全局警告处理
    app.config.warnHandler = (msg, vm, trace) => {
      monitor.reporter.send('error', {
        type: 'vue-warn',
        message: msg,
        trace,
        component: vm?.$options?.name || 'anonymous',
        timestamp: Date.now()
      })
    }
  }
} 